package com.boot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * <h3>springboot04-web-crud</h3>
 * <p>登录跳转dashboard</p>
 *
 * @author : 你的名字
 * @date : 2020-03-01 16:02
 **/
@Controller
public class LoginController {
    @PostMapping("/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String, Object> map,
                        HttpSession session) {
        if (!StringUtils.isEmpty(username) && "123456".equals(password)) {
            //登录成功，防止表单重复提交，可以重定向到主页
            session.setAttribute("loginUser", username);
//            return "redirect:/main.html";
            return "redirect:https://www.baidu.com";
        } else {
            map.put("msg", "用户名密码错误");
            return "login";
        }
    }
}
